Add CompletableFuture-based executeAsync overloads to fluent Async for simpler async composition.#782
Conversation
httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Async.java
Outdated
Show resolved
Hide resolved
| @@ -39,15 +48,93 @@ | |||
| */ | |||
| public class Async { | |||
There was a problem hiding this comment.
This class needs a thread-safety policy
There was a problem hiding this comment.
I just add Contract
httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Async.java
Outdated
Show resolved
Hide resolved
| * | ||
| * @since 5.7 | ||
| */ | ||
| public <T> CompletableFuture<T> executeAsync(final Request request, final HttpClientResponseHandler<T> handler) { |
There was a problem hiding this comment.
Is there a reason why we can't push this down into HttpAsyncClient? Seems like this would work as a simple default interface method to adapt the older continuation-passing API to the new promise (CompletableFuture) based API.
There was a problem hiding this comment.
Wait, I'm confused. This class provides an async API for synchronous request execution?
There was a problem hiding this comment.
Wait, I'm confused. This class provides an async API for synchronous request execution?
@rschmitt Fluent is a wrapper around the classic HttpClient with simplified APIs for most common use cases. Async in Fluent is indeed just a wrapper around multi-threaded executor and synchronous request execution.
This is historic and goes back to the early days of HttpClient 4.x
There was a problem hiding this comment.
Wait, I'm confused. This class provides an async API for synchronous request execution?
Fluent is built on the classic client. The new CompletableFuture methods are just adapters over the existing callback-based API.
There was a problem hiding this comment.
Well, I think it's weird to add CompletableFuture to this API before we've added it to the API of the async client.
…r simpler async composition. Provide an optional bounded default executor with configurable thread and queue limits. Keep existing Future-based API and default execution behavior unchanged.
31b22c2 to
d2f2ed4
Compare
|
If there no objection I'm going to merge this PR |
This change improves the fluent Async API without altering existing behaviour or contracts. It adds executeAsync overloads returning CompletableFuture, including variants that also invoke the existing FutureCallback, making it easier to compose and aggregate asynchronous request execution using standard Java primitives. It also introduces an optional owned bounded default executor, configurable in terms of thread count and queue capacity, for applications that prefer not to manage their own ExecutorService. The existing Future-based methods and the default execution model remain unchanged.